use std::collections::HashMap;
use std::sync::Mutex;

use lazy_static::lazy_static;

lazy_static! {
    static ref LOCAL_VARIABLES: Mutex<HashMap<String, Box<dyn std::any::Any + Send>>> = Mutex::new(HashMap::new());
}

pub fn put_local<S: Into<String>, T: 'static + Send>(key: S, value: T) {
    let mut local_variables = LOCAL_VARIABLES.lock().unwrap();
    local_variables.insert(key.into(), Box::new(value));
}

pub fn get_local<T: 'static + Send + Clone>(key: &str) -> Option<T> {
    let local_variables = LOCAL_VARIABLES.lock().unwrap();
    local_variables.get(key).and_then(|v| v.downcast_ref::<T>().cloned())
}
